//
//  WLFeedbackVController.m
//  WanLian
//
//  Created by muzhuang on 2018/10/24.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLFeedbackVController.h"
#import "UITextView+WJPlaceholder.h"
static int MaxSize = 300;
@interface WLFeedbackVController ()<UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>
{
    UIButton *btnProduct;
    UIButton *btnFunction;
    UIButton *btnOthers;
    NSInteger feedType;
    
    UITextView *textFeed;
    UILabel     *labLimit;
    UILabel     *labImg;
    UIButton    *btnImg;
    UIButton    *btnDelete;
    UIImage     *selectedImg;
    UITextField *textPhone;
    
}

@property (nonatomic, strong) UIScrollView  *feedScroller;
@property (nonatomic, assign) NSInteger selectImages;
@property (nonatomic, assign) NSInteger pageNum;
@property (nonatomic, weak) UIView *feedTypeContainerView;

@end

@implementation WLFeedbackVController
- (void)dealloc
{
    [textFeed removeFontObserver];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)getFeedbackType {
    WLWkSelf
    NSDictionary *params = @{
                                @"conditons":@{},
                                @"page":@{
                                    @"page":@(_pageNum),
                                    @"num":@10
                                }
                             };
    [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"question/type/list" withParamsDic:params success:^(NSDictionary *successDict) {
        __strong __typeof(weakSelf) strongSelf = weakSelf;
        if (successDict[@"object"]) {
            [strongSelf createFeedTypeBtnWithArr:successDict[@"object"]];
        }
    } failure:^(NSString *errorMsg, NSInteger errorTag) {
        [weakSelf showHUDMessage:errorMsg];
    } error:^(NSError *error) {
    } inView:nil];
}
- (void)createFeedTypeBtnWithArr:(NSArray *)feedTypeArr {
    NSMutableArray *reFeedTypeArr = [NSMutableArray array];
    for (NSDictionary *dict in feedTypeArr) {
        if ([[dict objectForKey:@"enable"] integerValue] == 1) {
            [reFeedTypeArr addObject:dict];
        }
    }
    for (UIView * subView in self.feedTypeContainerView.subviews) {
        [subView removeFromSuperview];
    }
    for (int i = 0; i < reFeedTypeArr.count; i ++) {
        NSDictionary *typeDict = reFeedTypeArr[i];
        CGFloat logicW = Screen_width / reFeedTypeArr.count;
        CGFloat xMagzin = (logicW - WLScaleX(90)) / 2;
        CGFloat BtnX = xMagzin + i *logicW;
        
        UIButton *typeBtn = [[UIButton alloc] initWithFrame:CGRectMake(BtnX, 0, WLScaleX(90), WLScaleX(35))];
        [typeBtn setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
        [typeBtn setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
        typeBtn.titleLabel.font = [WLCommonTool fontTypePingFangSCRegular:14];
        [typeBtn setTitleColor:wlDarkGrayColor forState:UIControlStateNormal];
        [typeBtn setTitle:typeDict[@"modelName"] forState:UIControlStateNormal];
        typeBtn.tag = [typeDict[@"id"] integerValue];
        [typeBtn addTarget:self action:@selector(feedTypeAction:) forControlEvents:UIControlEventTouchUpInside];
        [_feedTypeContainerView addSubview:typeBtn];
        if (i == 0) {
            typeBtn.selected = YES;
            feedType = typeBtn.tag;
        }
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"意见反馈";
    _pageNum = 1;
    [self getFeedbackType];
    _feedScroller = [[UIScrollView alloc] init];
    _feedScroller.showsVerticalScrollIndicator = NO;
    _feedScroller.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_feedScroller];
    WLWkSelf
    [_feedScroller mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view.mas_top).offset(WLScaleX(20));
        make.left.bottom.right.equalTo(weakSelf.view);
    }];
//
    UILabel *labFeedType = [[UILabel alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(10), 200, 25)];
    labFeedType.font = [WLCommonTool fontTypePingFangSCMedium:17];
    labFeedType.textColor = wlBlackColor;
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"意见反馈(您遇到的问题类型)"];
    [attrStr addAttribute:NSFontAttributeName
                      value:[WLCommonTool fontTypePingFangSCRegular:14]
                      range:NSMakeRange(4, attrStr.length-4)];
    [attrStr addAttribute:NSForegroundColorAttributeName value:wlLightTextColor range:NSMakeRange(4,attrStr.length-4)];
    labFeedType.attributedText = attrStr;
    [_feedScroller addSubview:labFeedType];
    UIView *feedTypeContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, WLScaleX(50), Screen_width, WLScaleX(35))];
    feedTypeContainerView.backgroundColor = [UIColor whiteColor];
    [_feedScroller addSubview:feedTypeContainerView];
    _feedTypeContainerView = feedTypeContainerView;
    
//
//    btnProduct = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(50), WLScaleX(90), WLScaleX(35))];
//    [btnProduct setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
//    [btnProduct setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
//    btnProduct.titleLabel.font = [WLCommonTool fontTypePingFangSCRegular:14];
//    [btnProduct setTitleColor:wlDarkGrayColor forState:UIControlStateNormal];
//    [btnProduct setTitle:@" 产品建议" forState:UIControlStateNormal];
//    btnProduct.tag = 0;
//    [btnProduct addTarget:self action:@selector(feedTypeAction:) forControlEvents:UIControlEventTouchUpInside];
//    [_feedScroller addSubview:btnProduct];
//    btnProduct.selected = YES;
//    btnOthers = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16+210), WLScaleX(50), WLScaleX(70), WLScaleX(35))];
//    [btnOthers setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
//    [btnOthers setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
//    btnOthers.titleLabel.font = [WLCommonTool fontTypePingFangSCRegular:14];
//    [btnOthers setTitleColor:wlDarkGrayColor forState:UIControlStateNormal];
//    [btnOthers setTitle:@" 其他" forState:UIControlStateNormal];
//    btnOthers.tag = 2;
//    [btnOthers addTarget:self action:@selector(feedTypeAction:) forControlEvents:UIControlEventTouchUpInside];
//    [_feedScroller addSubview:btnOthers];

    textFeed = [[UITextView alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(50+35+30), WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(85))];
    textFeed.delegate = self;
    textFeed.font = [WLCommonTool fontTypePingFangSCRegular:14];
    textFeed.textColor = wlBlackColor;
    textFeed.placeholdLabel.font = [WLCommonTool fontTypePingFangSCRegular:12];
    textFeed.placeholderColor = wlLightTextColor;
    textFeed.placeholder = @"亲，我们非常重视您给我们提出的宝贵意见，帮助我们不断完善产品，谢谢！";
    [_feedScroller addSubview:textFeed];

    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(115+85), WIDTH_SCREEN_WL-WLScaleX(32), 1)];
    lineView.backgroundColor = wlUIColorRGB(0xF2F2F2);
    [_feedScroller addSubview:lineView];

    labLimit = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH_SCREEN_WL-WLScaleX(16)-50, WLScaleX(200)-20, 40, 20)];
    labLimit.textAlignment = NSTextAlignmentRight;
    labLimit.font = [WLCommonTool fontTypePingFangSCRegular:12];
    labLimit.textColor = wlUnderlineColor;
    labLimit.text = [NSString stringWithFormat:@"%d",MaxSize];
    [_feedScroller addSubview:labLimit];

    labImg = [[UILabel alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(200+20), 200, 25)];
    labImg.font = [WLCommonTool fontTypePingFangSCMedium:17];
    labImg.textColor = wlBlackColor;
    NSMutableAttributedString *attrImg =  [self attributedStrWithPictureNum:self.selectImages];
    labImg.attributedText = attrImg;
    [_feedScroller addSubview:labImg];
//
    UIView *vPhoto = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(220+15)+25, WLScaleX(55), WLScaleX(55))];
    CAShapeLayer *borderLayer = [CAShapeLayer layer];
    borderLayer.bounds = vPhoto.bounds;
    borderLayer.position = CGPointMake(CGRectGetMidX(vPhoto.bounds), CGRectGetMidY(vPhoto.bounds));

    borderLayer.path = [UIBezierPath bezierPathWithRect:borderLayer.bounds].CGPath;
//    borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:CGRectGetWidth(borderLayer.bounds)/2].CGPath;
    borderLayer.lineWidth = 1.0;
    //虚线边框
    borderLayer.lineDashPattern = @[@4, @4];
    //实线边框
    //    borderLayer.lineDashPattern = nil;
    borderLayer.fillColor = [UIColor clearColor].CGColor;
    borderLayer.strokeColor = wlUnderlineColor.CGColor;
    [vPhoto.layer addSublayer:borderLayer];
    [_feedScroller addSubview:vPhoto];

    UIImageView *ivPhoto = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"feed_photo"]];
    ivPhoto.center = vPhoto.center;
    [_feedScroller addSubview:ivPhoto];

    btnImg = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(220+15)+25, WLScaleX(55), WLScaleX(55))];
    [btnImg addTarget:self action:@selector(addPhotoAction) forControlEvents:UIControlEventTouchUpInside];
    [_feedScroller addSubview:btnImg];

    btnDelete = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16+55)-9, CGRectGetMinY(btnImg.frame)-9, 18, 18)];
    [btnDelete setImage:[UIImage imageNamed:@"photo_delete"] forState:UIControlStateNormal];
    [btnDelete addTarget:self action:@selector(deletePhotoAction) forControlEvents:UIControlEventTouchUpInside];
    [_feedScroller addSubview:btnDelete];
    btnDelete.hidden = YES;

    UILabel *labTip = [[UILabel alloc] initWithFrame:CGRectMake(WLScaleX(16+55+8), WLScaleX(235+55)+5, 50, 20)];
    labTip.font = [WLCommonTool fontTypePingFangSCRegular:12];
    labTip.textColor = wlLightTextColor;
    labTip.text = @"(选填)";
    [_feedScroller addSubview:labTip];

    textPhone = [[UITextField alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(235+55+35)+25, WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(35))];
    textPhone.delegate = self;
    textPhone.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"填写您的手机或邮箱(选填)" attributes:@{NSFontAttributeName:[WLCommonTool fontTypePingFangSCRegular:12],NSForegroundColorAttributeName:wlLightTextColor}];
    [_feedScroller addSubview:textPhone];

    UIView *linePhone = [[UIView alloc] initWithFrame:CGRectMake(WLScaleX(16), WLScaleX(235+55+35+35)+25, WIDTH_SCREEN_WL-WLScaleX(32), 1)];
    linePhone.backgroundColor = wlUIColorRGB(0xF2F2F2);
    [_feedScroller addSubview:linePhone];

    UIButton *btnSubmit = [[UIButton alloc] initWithFrame:CGRectMake(WLScaleX(16), CGRectGetMaxY(linePhone.frame)+WLScaleX(40), WIDTH_SCREEN_WL-WLScaleX(32), WLScaleX(47))];
    CAGradientLayer *gradientBtn = [CAGradientLayer layer];
    gradientBtn.frame = btnSubmit.bounds;  // 设置显示的frame
    gradientBtn.colors = @[(__bridge id)wlUIColorRGB(0x1A59E2).CGColor,(__bridge id)wlUIColorRGB(0x2292F5).CGColor]; // 设置渐变颜色
    gradientBtn.startPoint = CGPointMake(0, 0);
    gradientBtn.endPoint = CGPointMake(1, 0);
    [btnSubmit.layer insertSublayer:gradientBtn atIndex:0];

    btnSubmit.layer.cornerRadius = 5;
    btnSubmit.layer.masksToBounds = YES;
    btnSubmit.titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:16];
    [btnSubmit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnSubmit setTitle:@"提交" forState:UIControlStateNormal];
    [btnSubmit addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchUpInside];
    [_feedScroller addSubview:btnSubmit];
//    _feedScroller.mj_header = [WLFreshGifHeader headerWithRefreshingBlock:^{
//        weakSelf.tableMessage.mj_footer = nil;
//        [weakSelf.arrMsgs removeAllObjects];
//        weakSelf.pageNum = 1;
//        [self sendReqeust];
//    }];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBdWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keybdWillHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (NSMutableAttributedString *)attributedStrWithPictureNum:(NSInteger)picNum {
    
    NSMutableAttributedString *attrImg = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"上传图片(%ld/1)", picNum]];
    [attrImg addAttribute:NSFontAttributeName
                    value:[WLCommonTool fontTypePingFangSCRegular:14]
                    range:NSMakeRange(4, attrImg.length-4)];
    [attrImg addAttribute:NSForegroundColorAttributeName value:wlLightTextColor range:NSMakeRange(4,attrImg.length-4)];
    return attrImg;
}
- (void)feedTypeAction:(UIButton *)btnType
{
    for (UIButton *btn in self.feedTypeContainerView.subviews) {
        btn.selected = NO;
    }
    feedType = btnType.tag;
    btnType.selected = YES;
}

- (void)submitAction
{
    [self.view endEditing:YES];
    if (textFeed.text.length<1) {
        [self showHUDMessage:@"请先输入您的意见"];
    }
    else if (selectedImg != nil)
    {
        [self uploadFeedImg];
    }
    else
    {
        [self commitAdvice:@[]];
    }
}

- (void)commitAdvice:(NSArray *)imgPathArr
{
    NSString *phone = @"";
    if (textPhone.text.length>0) {
        phone = textPhone.text;
    }
    if (!imgPathArr) {
        return;
    }
    NSMutableString *mStr = [NSMutableString new];
    if (imgPathArr.count > 0) {
        [mStr appendString:@"["];
        for (int i = 0; i < imgPathArr.count; i ++) {
            NSString *imagePath = imgPathArr[i];
            [mStr appendString:@"\""];
            [mStr appendString:imagePath];
            [mStr appendString:@"\""];
            if (i == imgPathArr.count - 1) {
                [mStr appendString:@"]"];
            } else {
                [mStr appendString:@","];
            }
        }
    }
    
    NSDictionary *params = @{@"content":textFeed.text,@"remark":phone,@"title":@"",@"typeId":@(feedType),@"imgPath":mStr};
    WLWkSelf
    [WLHttpManager WLRequestMethod:RequestTypePost urlStr:@"question/add" withParamsDic:params success:^(NSDictionary *successDict) {
        [weakSelf hideHUD];
        [weakSelf showHUDMessage:successDict[@"message"]];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        });
    } failure:^(NSString *errorMsg, NSInteger errorTag) {
        [weakSelf hideHUD];
        [weakSelf showHUDMessage:errorMsg];
    } error:^(NSError *error) {
        [weakSelf hideHUD];
        [weakSelf showHUDMessage:@"请求失败"];
    } inView:nil];
}

- (void)uploadFeedImg
{
    NSString *type = @"jpg";
    NSData *data = UIImageJPEGRepresentation(selectedImg, 0.5);
    if (data==nil) {
        data = UIImagePNGRepresentation(selectedImg);
        type = @"png";
    }
    NSDateFormatter *dateformat=[[NSDateFormatter  alloc]init];
    [dateformat setDateFormat:@"yyMMddHHmmss"];
    NSString *strTime = [dateformat stringFromDate:[NSDate date]];
    NSString *fileName = [NSString stringWithFormat:@"%@.%@",strTime,type];
    
    WLWkSelf
    [self showHUDProgressHUD];
    NSMutableArray *imagePathArr = [NSMutableArray new];
    [WLHttpManager WLUpDownloadPost:@"https://www.zeerong.com/router/upload/file/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:data name:@"file" fileName:fileName                                mimeType:@"image/jpeg"];
    } progress:^(NSProgress *uploadProgress) {
        
    } success:^(NSDictionary *successDict) {
        if (successDict[@"url"]) {
            [imagePathArr addObject:successDict[@"url"]];
            [weakSelf commitAdvice:imagePathArr];
        }
    } failure:^(NSString *errorMsg, NSInteger errorTag) {
        [weakSelf hideHUD];
        [weakSelf showHUDMessage:errorMsg];
    } error:^(NSError *error) {
        [weakSelf hideHUD];
        [weakSelf showHUDMessage:@"请求失败"];
    } inView:nil];
}

#pragma mark - Photo Action
- (void)deletePhotoAction
{
    [btnImg setBackgroundImage:nil forState:UIControlStateNormal];
    selectedImg = nil;
    btnDelete.hidden = YES;
    NSMutableAttributedString *attrImg =  [self attributedStrWithPictureNum: -- self.selectImages];
    labImg.attributedText = attrImg;
}

- (void)addPhotoAction
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *photo = [UIAlertAction actionWithTitle:@"我的相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self chooseHeadimgAction:UIImagePickerControllerSourceTypePhotoLibrary];
    }];
//                [photo setValue:wlblueColor forKey:@"_titleTextColor"];
    [alertController addAction:photo];
    
    UIAlertAction *camera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self chooseHeadimgAction:UIImagePickerControllerSourceTypeCamera];
    }];
//                [camera setValue:wlblueColor forKey:@"_titleTextColor"];
    [alertController addAction:camera];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    //                [cancel setValue:wlblueColor forKey:@"_titleTextColor"];
    [alertController addAction:cancel];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)chooseHeadimgAction:(UIImagePickerControllerSourceType)type
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = type;
    imagePickerController.mediaTypes = @[(__bridge NSString *)kUTTypeImage];
//    imagePickerController.allowsEditing = YES;
    imagePickerController.navigationBar.translucent=NO;
    [imagePickerController.navigationBar setTintColor:wlBlackColor];
    [self presentViewController:imagePickerController animated:YES completion:nil];
}

#pragma mark - UIImagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    NSString  *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
    {
        selectedImg = [info objectForKey:UIImagePickerControllerOriginalImage];
        [btnImg setBackgroundImage:selectedImg forState:UIControlStateNormal];
        btnDelete.hidden = NO;
        NSMutableAttributedString *attrImg =  [self attributedStrWithPictureNum: ++self.selectImages];
        labImg.attributedText = attrImg;
    }
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - UITextView
- (void)textViewDidChange:(UITextView *)textView
{
    long count = MAX(0, (int)(MaxSize - textView.text.length));
    labLimit.text = [NSString stringWithFormat:@"%ld",count];
    if (textView.text.length > MaxSize) {
        textView.text = [textView.text substringToIndex:MaxSize];
    }
//    return;
    /*
    NSString *lang = [[[UITextInputMode activeInputModes] firstObject] primaryLanguage];//当前的输入模式
    if ([lang isEqualToString:@"zh-Hans"])
    {
        UITextRange *range = [textView markedTextRange];
        UITextPosition *start = range.start;
        UITextPosition*end = range.end;
        NSInteger selectLength = [textView offsetFromPosition:start toPosition:end];
        NSInteger contentLength = textView.text.length - selectLength;
        if (contentLength < 300)
        {
            labLimit.text = [NSString stringWithFormat:@"%ld", 300 - contentLength];
        }
        else
        {
            labLimit.text = @"0";
        }
    }
    else
    {
        labLimit.text = [NSString stringWithFormat:@"%ld", 300-textView.text.length];
    }
    */
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //如果是删除减少字数，都返回允许修改
    if ([text isEqualToString:@""]) {
        return YES;
    }
    if (range.location>= 300)
    {
        return NO;
    }
    else
    {
        return YES;
    }
}

- (void)keyBdWillShow:(NSNotification *)user
{
    CGRect keyboardRect = [user.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat maxY = CGRectGetMaxY(textPhone.frame)+WL_NavTopHeight+WLScaleX(20);
    CGFloat keyBoardY = keyboardRect.origin.y;
    if (maxY > keyBoardY) {
        _feedScroller.contentOffset = CGPointMake(0, maxY-keyBoardY+50);
    }
}
- (void)keybdWillHidden:(NSNotification *)user
{
    _feedScroller.contentOffset = CGPointZero;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

//- (void)textFieldDidBeginEditing:(UITextField *)textField
//{
//
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
